package com.us.simple.sys.controller;

import com.us.simple.common.advice.Rest;
import com.us.simple.common.advice.RestBody;
import com.us.simple.common.advice.ServiceException;
import com.us.simple.common.context.RequestContextHolder;
import com.us.simple.sys.entity.UserInfo;
import com.us.simple.sys.service.IUserInfoService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: wangziqian
 * @Date: 2024-05-15
 */
@RestController
@RequestMapping("/test")
@Slf4j
@Api( tags = "测试")
public class TestInfoController {

    @Autowired
    private IUserInfoService userInfoService;

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping(value = "/getList")
    public Rest getList() {
        List<UserInfo> list = userInfoService.list();
        String userId = RequestContextHolder.get("username");;
        System.out.println("当前登录人id="+userId );
        return RestBody.okData(list);
    }

    @GetMapping(value = "/getListCount")
    public Rest getListCount() {
        Integer I = userInfoService.getListCount();
        Boolean redisResult = redisTemplate.hasKey("sys_dict:sys_common_status");
        return RestBody.okData(I);
    }

    @GetMapping(value = "/gettest1")
    public void gettest1() {
        throw new ServiceException("异常",999);
    }

}
